<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>${className}</title>
    <script src="../js/vue.min.js"></script>
    <script src="../js/jquery-2.1.0.js"></script>
    <script src="../js/jquery.form.js"></script>
    <link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css"/>
    <script src="../layer/layer.js"></script>
</head>

<body>
<div class="container">

    <div id="app">
        <form id="my_form" enctype="multipart/form-data" method="post">
            <input name="id" v-model="obj.id" hidden="hidden"/>
         <#list fieldList as d>
             <#if d.type=='String'>
                <label for="${d.name}_input">${d.name}</label>
                <input type="text" class="form-control" id="${d.name}_input" name="${d.name}" v-model="obj.${d.name}"
                       placeholder="${d.name}">
             </#if >
             <#if d.type=='Integer'&&d.name!='id'>
                <label for="${d.name}_input">${d.name}</label>
                <input type="number" class="form-control" id="${d.name}_input" name="${d.name}" v-model="obj.${d.name}"
                       placeholder="${d.name}">
             </#if >
             <#if d.type=='Boolean'>
                <label>${d.name}</label>
                <div>
                    <input type="radio" name="${d.name}" v-model="obj.${d.name}" id="${d.name}_radio1" value="true">
                    <label class="left_label" for="${d.name}_radio1">在线</label>
                    <input type="radio" name="${d.name}" v-model="obj.${d.name}" id="${d.name}_radio2" value="false">
                    <label class="left_label" for="${d.name}_radio2">隐藏</label>
                </div>
             </#if >
         </#list>

            <div>
                <button type="button" @click="com_the_form()" class="btn btn-primary pull-right">提交</button>
            </div>
        </form>
    </div>
</div>
<script>
    new Vue({
        el: '#app',
        data: {
            id: get_parameter("id"),
            obj: {}
        },
        created() {
            var vm = this;
            if (vm.id > 0) {
                $.post("../${className}/findById", {id: vm.id}, function (data) {
                    vm.obj = data.obj;
                });
            }
        },
        methods: {
            com_the_form() {
                //默认是添加
                var vm = this;
                var myUrl = "../${className}/add"
                //有id则是修改
                if (vm.id > 0) {
                    myUrl = "../${className}/updateNotNull";
                }
                $("#my_form").attr("action", myUrl).ajaxSubmit({
                    success: function (data) {
                        if (data.ok) {
                            layer.alert(data.msg, function () {
                                parent.layer.close(parent.layer.getFrameIndex(window.name));
                            })
                        } else {
                            layer.alert(data.msg)
                        }
                    }
                });
            }

        }
    })

    function get_parameter(name) {
        var lot = location.search;
        var reg = new RegExp(".*" + name + "\\s*=([^=&#]*)(?=&|#|).*", "g");
        return decodeURIComponent(lot.replace(reg, "$1"));
    }


</script>
</body>
</html>